#include "Hero.h"
#include <stdio.h>

Hero::Hero() 
{
	
}


Hero::Hero(const char * f, int x, int y)
         :imageFileName(f)
{
	Sprite::x = x;
	Sprite::y = y;

}
Hero::~Hero()
{
	
}

void Hero::init()
{
	img = IMG_Load(this->imageFileName);
	if (img == NULL)
	{
		printf("error miss image\n");
	}
	m_heroTexture = SDL_CreateTextureFromSurface(Sprite::m_renderer, img);
	rect.x = x;
	rect.y = y;
	rect.h = img->h;
	rect.w = img->w / 8;
	for (i = 0; i < 8; i++) {
		walks[i].w = img->w / 8;
		walks[i].h = img->h;
		walks[i].x = i * walks[i].w;
		walks[i].y = 0;
	}
}

void Hero::onMouse(){
     this->done = this->done == 0 ? 1 : 0;
}

void Hero::render()
{
      
	SDL_RenderCopy(Sprite::m_renderer, m_heroTexture, &walks[i], &rect);
	if(done == 0){
       i = (i + 1) % 8;
	   //不是原地行走，是前进   
	   rect.x = (rect.x + 5) % (rect.w * 8); 
	}	
}

